
import { Logger } from "./Logger";

const child_process = require('child_process');

export class ShellHelper {

    public static async getOnline(port: number = 7520):Promise<number> {
        // netstat -an |grep 'ESTABLISHED' |grep -i '9201' |wc -l
        let cmd: string = "netstat -an |grep 'ESTABLISHED' |grep -i '" + port + "' |wc -l"
        return new Promise((resolve, reject) => {
            child_process.exec(cmd, (error, stdout, stderr) => {
                if (error) {
                    console.log("执行命令出错=getOnline=", error, stderr);
                    return
                }
                let online:number = parseInt(stdout)
                Logger.log("getOnline===", stdout, online)
                resolve(online)
            });
        })
    }
}